package cn.csxw.openchina.ui.activity;

import android.graphics.Color;
import android.support.design.widget.TabLayout;
import android.support.v4.view.ViewPager;
import android.view.View;

import java.util.ArrayList;
import java.util.List;

import butterknife.BindView;
import cn.csxw.openchina.R;
import cn.csxw.openchina.base.BaseActivity;
import cn.csxw.openchina.base.BaseContentPagerAdapter;
import cn.csxw.openchina.base.BaseRefreshFragment;
import cn.csxw.openchina.ui.fragment.exerciseFragment.MyExerciseFragment;
import cn.csxw.openchina.ui.fragment.exerciseFragment.RecentlyExerciseFragment;

/**
 * 活动界面的Activity
 */

public class ExerciseActivity extends BaseActivity {
    @BindView(R.id.tableLayout)
    TabLayout mTableLayout;
    @BindView(R.id.viewPager)
    ViewPager mViewPager;
    private List<BaseRefreshFragment> mFragments = new ArrayList<>();
    private static final String[] name = new String[]{"近期活动", "我的活动"};
    private BaseContentPagerAdapter mAdapter;
    @Override
    public int getLayoutRes() {
        return R.layout.activity_exercise;
    }

    @Override
    public void initView() {
        mFragments.add(new RecentlyExerciseFragment());
        mFragments.add(new MyExerciseFragment());
        //初始化ViewPager 并且关联tabLayout
        initViewPager();
    }

    //初始化ViewPager 并且关联tabLayout
    private void initViewPager() {
        //遍历Fragment 并把他们填充在Activity中
        if(mAdapter== null){
            mAdapter = new
                    BaseContentPagerAdapter(getSupportFragmentManager());
            mViewPager.setAdapter(mAdapter);
            mTableLayout.setTabTextColors(Color.GRAY,Color.GREEN);
            mTableLayout.setupWithViewPager(mViewPager);
        }

    }

    @Override
    public void initListener() {
    }

    @Override
    public void initData() {
        mAdapter.setSwipeList(mFragments, name);
    }

    @Override
    public void onClick(View v, int id) {

    }
}
